package com.lsb.controller;

import com.lsb.pojo.RegionStats;
import com.lsb.service.DataService;
import com.lsb.vo.ChartVO;
import com.lsb.vo.RealChartVO;
import com.lsb.vo.StateChartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：liusibo
 * @description：TODO
 * @date ：2021/4/27 17:54
 */
@RestController
@RequestMapping("/data")
public class DataController {
    @Autowired
    private DataService dataService;

    @RequestMapping("/all")
    public List<RegionStats> getAllStats(){
        return dataService.getAllStats();
    }

    @RequestMapping("/byCountryName/{countryName}")
    public List<RegionStats> getStatsByCountryName(@PathVariable("countryName") String countryName){
        return dataService.getByCountryName(countryName);
    }

    @RequestMapping("/byStateName/{stateName}")
    public List<RegionStats> getStatsByStateName(@PathVariable("stateName") String stateName){
        return dataService.getByStateName(stateName);
    }

    @RequestMapping("/byId")
    public List<RegionStats> getStatsById(@RequestParam("id")Integer id){
        return dataService.getById(id);
    }

    @RequestMapping("/chart")
    public RealChartVO getChartVO(){
        RealChartVO vo = new RealChartVO();
        dataService.getChartVO().forEach(e->{
            vo.getX().add(e.getDate());
            vo.getY().add(e.getNum());
        });
        return vo;
    }

    @RequestMapping("/statechart/{id}")
    public StateChartVO getStateChartVO(@PathVariable("id")Integer id){
        return dataService.getStateChartVOById(id);
    }
}
